$.namespace("user.address.detail");

/**
 * 画面初始化处理
 */
user.address.detail.init = function() {
	user.address.detail.initForm();
};

/**
 * 
 */
user.address.detail.initForm = function() {
	// 更新的场合
	if($("#mode").val() == 1) {
		$("#address_id").val(localStorage.getItem("addressId"));
		$("#user_name").val(localStorage.getItem("userName"));
		$("#nick_name").val(localStorage.getItem("nickName"));
		$("#tel_phone").val(localStorage.getItem("telPhone"));
		$("#post_code").val(localStorage.getItem("postCode"));
		$("#address").val(localStorage.getItem("address"));
		
		localStorage.removeItem("addressId");
		localStorage.removeItem("userName");
		localStorage.removeItem("nickName");
		localStorage.removeItem("telPhone");
		localStorage.removeItem("postCode");
		localStorage.removeItem("address");
	}
};

/**
 * 关闭窗口
 */
user.address.detail.close = function(){
	$('#"userAddressEditWin"').window('close');
};

user.address.detail.save = function() {
	$.messager.confirm("确认", "您确定要更新商品信息吗？", function(ok) {
		if(ok) {
			$('#saveButton').attr('disabled',"disabled");
			$.messager.progress({
				title : "提示",
				text : "数据保存中，请等待...",
			});
			
			$.ajax({
				type : 'POST',
		        url : $.ctx + "/user/address/saveOrUpdate",
		        data : {
		        	address_id	: $.trim($("#address_id").val()),
		        	user_name 	: $.trim($("#user_name").val()),
		        	nick_name	: $.trim($("#nick_name").val()),
		        	tel_phone	: $.trim($("#tel_phone").val()),
		        	post_code	: $.trim($("#post_code").val()),
		        	address		: $.trim($("#address").val())
		        },
		        success : function(result) {
		        	$.messager.progress('close');
		        	$('#saveButton').removeAttr('disabled');
		            if (result.isSuccess && result.rslt_flag == "0") {
		            	$.messager.alert("提示", "保存成功");
		            	user.address.main.g$mainGrid.datagrid('reload');
		            	$('#userAddressEditWin').window('close');
		            } else if(result.rslt_flag == "-1"){
		            	$.messager.alert(common.msg.type.info, '保存失败!');
		            }
		        },
		        error: function(error) {
		        	$('#saveButton').removeAttr('disabled');
		        }
		    });
		}
	});
}
